from api_server.db.models.z_rectify import ZRectifyData
from api_server.db.session import with_session, asdict
from configs import logger
from sqlalchemy import desc, asc


@with_session
def delete_rectify(session, codes=None):
    '''
    批量删除政数据
    '''
    try:
        query = session.query(ZRectifyData).filter(ZRectifyData.audit_code.in_(codes))
        query.delete(synchronize_session=False)
        session.commit()
        return True
    except Exception as e:
        logger.error(e)
    return False


@with_session
def get_rectify_detail(session, code=None) -> dict:
    '''
    获取整改详细数据
    '''
    rectify = session.query(ZRectifyData).filter(ZRectifyData.audit_code == code).first()
    if rectify:
        return {
            "id": rectify.id,
            "audit_code": rectify.audit_code,
            "audit_report_name": rectify.audit_report_name,
            "audit_report_date": rectify.audit_report_date,
            "audit_unit": rectify.audit_unit,
            "question_type": rectify.question_type,
            "question_summary": rectify.question_summary,
            "question_detail": rectify.question_detail,
            "audit_money": rectify.audit_money,
            "rectify_advice": rectify.rectify_advice,
            "audit_manager": rectify.audit_manager,
            "audit_dept": rectify.audit_dept,
            "rectify_hand": rectify.rectify_hand,
            "recitify_result": rectify.recitify_result,
        }
    return None
